<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<script type="text/javascript" src="${ctx}/scripts/checktool.js"></script>
<link rel="stylesheet" type="text/css" href="${ctx}/styles/sty_reglog.css" media="screen"/>
<div class="logreg_logo">
	<div class="logreg_logodiv">
		<a class="logreg_logoa" href="#"></a>
	</div>
</div>
<p class="regtitle">只需10秒，您就即可轻松完成注册！赶快填写您的信息吧</p>
<div class="regmain">
<form id="f_register" action="<c:url value='/h/register.do'/>" method="post" onsubmit="return goRegister();">
	
	<dl id="dl_account_error" class="regmaindl" style="display:none;">
		<dt>
		</dt>
		<dd>
			<div id="div_account_error"></div>
		</dd>
	</dl>
	<dl class="regmaindl">
		<dt>
			<span class="sf00">*</span><fmt:message key="html.register.username"/>：
		</dt>
		<dd>
			<input class="regform" type="text" id="register_username" name="account" onfocus="clearErrorDiv('div_account_error')" onblur="validateAccount()"/>
		</dd>
		<dd>请您使用：-，_，数字，字母(6-15位)</dd>
	</dl>
	
	<dl id="dl_nickname_error" class="regmaindl" style="display:none;">
		<dt>
		</dt>
		<dd>
			<div id="div_nickname_error"></div>
		</dd>
	</dl>
	<dl class="regmaindl">
		<dt>
			<span class="sf00">*</span><fmt:message key="html.register.nickname"/>：
		</dt>
		<dd>
			<input class="regform" type="text" id="register_nickname" name="nick" onfocus="clearErrorDiv('div_nickname_error')" onblur="validateNickname()"/>
		</dd>
		<dd></dd>
	</dl>
	
	<dl id="dl_email_error" class="regmaindl"  style="display:none;">
		<dt>
		</dt>
		<dd>
			<div id="div_email_error"></div>
		</dd>
	</dl>
	<dl class="regmaindl">
		<dt>
			<span class="sf00">*</span><fmt:message key="html.register.email"/>：
		</dt>
		<dd>
			<input class="regform" type="text" id="register_email" name="email"  onfocus="clearErrorDiv('div_email_error')" onblur="validateEmail()"/>
		</dd>
		<dd>请正确填写您的常用邮箱！</dd>
	</dl>
	
	<dl id="dl_password_error" class="regmaindl" style="display:none;">
		<dt>
		</dt>
		<dd>
			<div id="div_password_error"></div>
		</dd>
	</dl>
	<dl class="regmaindl">
		<dt>
			<span class="sf00">*</span><fmt:message key="html.register.password"/>：
		</dt>
		<dd>
		<input class="regform" type="text" id="register_password" name="password" onfocus="clearErrorDiv('div_password_error')" onblur="validatePassword()"/>
		</dd>
		<dd>请您使用：-，_，数字，字母(6-15位)</dd>
	</dl>
	<dl class="regmaindl">
		<dt>性 别：</dt>
		<dd>
			<select name="gender" style="width:120px">
				<option value="1">帅哥</option>
				<option value="2">美女</option>
			</select>
		</dd>
	</dl>
	<p class="regbutdiv">
		<span class="marrigh10">
			<input class="loginbut" type="submit" value="立即注册" name=""/>
		</span>
		<span class="sHB00">
			已有注册号，点击
			<a class="lHc00" href="<c:url value='/h/gr.do'/>">登录</a>
		</span>
	</p>
</form>
</div>

<script type="text/javascript">
function goRegister(){
	var div_account_error = $("#div_account_error").html();
	var div_nickname_error = $("#div_nickname_error").html();
	var div_email_error = $("#div_email_error").html();
	var div_password_error = $("#div_password_error").html();
	if(div_account_error.length == 0 && div_nickname_error.length == 0 &&div_email_error.length == 0 &&div_password_error.length == 0){
		return true;
	}else{
		return false;
	}
}
function validateAccount(){
	var account = $("#register_username").val();
	if(CheckTool.checkUsername(account) == false){
		$("#div_account_error").html('<fmt:message key="html.register.error.username.pattern"/>');
		$("#dl_account_error").css("display", "block");
	}else{
		$.ajax({
			type : "POST",
			url : ctx + "/h/validacc.do",
			data : "account="+account,
			dataType:"xml",
			timeout:20000,
			sync : false,
			success : function(data){
				if($(data).find('result').text().toUpperCase().indexOf("TRUE") < 0){
					$("#div_account_error").html($(data).find('content').text());
					$("#dl_account_error").css("display", "block");
				}else{
					$("#div_account_error").html('');
					$("#dl_account_error").css("display", "none");
				}
			},
			error: function(){
				$("#div_account_error").html('<fmt:message key="html.register.error.username.exist"/>');
				$("#dl_account_error").css("display", "block");
			}
		});
	}
}
function validateNickname(){
	var nickname = $("#register_nickname").val();
	$.ajax({
		type : "POST",
		url : ctx + "/h/validnick.do",
		data : "nick="+nickname,
		dataType:"xml", 
		timeout:20000,
		sync : false,
		success : function(data){
			if($(data).find('result').text().toUpperCase().indexOf("TRUE") < 0){
				$("#div_nickname_error").html($(data).find('content').text());
				$("#dl_nickname_error").css("display", "block");
			}else{
				$("#div_nickname_error").html('');
				$("#dl_nickname_error").css("display", "none");
			}
		},
		error: function(){
			$("#div_nickname_error").html('<fmt:message key="html.register.error.nickname.exist"/>');
			$("#dl_nickname_error").css("display", "block");
		}
	});
}
function validateEmail(){
	var email = $("#register_email").val();
	if(CheckTool.checkEmail(email) == false){
		$("#div_email_error").html('<fmt:message key="html.register.error.email.pattern"/>');
		$("#dl_email_error").css("display", "block");
	}else{
		$("#div_email_error").html('');
		$("#dl_email_error").css("display", "none");
	}
}
function validatePassword(){
	var password = $("#register_password").val();
	if(CheckTool.checkPassword(password) == false){
		$("#div_password_error").html('<fmt:message key="html.register.error.password.pattern"/>');
		$("#dl_password_error").css("display", "block");
	}else{
		$("#div_password_error").html('');
		$("#dl_password_error").css("display", "none");
	}
}
</script>